package com.shumm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shumm.anno.Log;
import com.shumm.common.Result;
import com.shumm.mapper.ShangHanTiaoBianMapper;
import com.shumm.po.ShangHanTiaoBian;
import com.shumm.service.ShangHanTiaoBianService;
import com.shumm.vo.tbCF;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShangHanTiaoBianServiceImpl implements ShangHanTiaoBianService {
    @Autowired
    private ShangHanTiaoBianMapper mapper;

    public void setShangHanTiaoBianMapper(ShangHanTiaoBianMapper shangHanTiaoBianMapper) {
        this.mapper = shangHanTiaoBianMapper;
    }


    @Override
    public Result add(ShangHanTiaoBian tb) {
        Integer add = mapper.addTb(tb);
        if (add != null) {
            return Result.success();
        }
        return Result.error("未插入成功");
    }

    @Override
    public Result deleteById(Integer id) {
        if (mapper.deleteTb(id) > 0) {
            return Result.success();
        }
        return Result.error();
    }

    @Override
    public Result update(ShangHanTiaoBian tb) {
        mapper.updateTb(tb);
        return Result.success();
    }

    @Override
    public Result selectById(Integer id) {
        ShangHanTiaoBian shangHanTiaoBian = mapper.selectTbById(id);
        return Result.success(shangHanTiaoBian);
    }

    @Override
    public Result list() {
        List<ShangHanTiaoBian> list = mapper.list();
        return Result.success(list);
    }

    @Log(value = "93721")
    @Override
    public Result selectByContentOrComment(String content, String comment, String name, int size, int num) {
        PageHelper.startPage(num, size);
        List<tbCF> list = mapper.selectByContentOrComment(content, comment, name);
        Page<tbCF> pageInfo = (Page) list;
        return Result.success(pageInfo, mapper.selectByContentOrComment(content, comment, name).size());
    }

    @Override
    public Result count() {
        return Result.success(mapper.countAllTb());
    }
}
